package itesm.coler.service;

import itesm.coler.data.DAOFactory;
import itesm.coler.data.MessageDAO;
import itesm.coler.models.Message;
import itesm.coler.models.User;

import java.util.ArrayList;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Produces({"application/xml", "application/json"})
@Path("/message")
public class MessageResource {

	DAOFactory MySQLFactory = DAOFactory.getDAOFactory(DAOFactory.MySQL);
	// Create a DAO
	MessageDAO messageDAO = MySQLFactory.getMessageDAO();
	
	 @GET
	 public ArrayList<Message> getMessages() {
	    ArrayList<Message> messages = null;
	    messages = (ArrayList<Message>) messageDAO.findAll();
	    return messages;
	 }
	 
	 @GET
	 @Path("/messageId/{messageId}/")
	 @Produces({ "application/xml", "application/json" })
	 public Message getMessageByMessageId(@PathParam("messageId") int messageId) {
	    Message message = null;
	    message = (Message) messageDAO.findMessageByMessageId(messageId);
	    return message;
	 }
	 
	 @GET
	 @Path("/typeId/{typeId}/")
	 @Produces({ "application/xml", "application/json" })
	 public ArrayList<Message> getUsersByType(@PathParam("typeId") String typeId) {
	    ArrayList<Message> messages = null;
	    messages = (ArrayList<Message>) messageDAO.findMessageByMessageTypeId(typeId);
	    return messages;
	 }
}
